This document summarizes Haar wavelet transforms and Daubechies wavelet transforms, including their forward and inverse transforms. It provides MATLAB code implementations for 1D and 2D transforms using Haar, Daub4, Daub6, Daub5/3 and Daub4 wavelets. The transforms can be applied for multiple levels (levels 1 through k) to decompose signals into approximation and detail coefficients.
Poles and Zeros of a transfer function are the frequencies for which the value of the denominator and numerator of transfer function becomes zero respectively. poles and zeros define the performance of a system.
Abstract
キーの値による範囲検索が可能なキー順序保存型構造化オーバレイネットワークは多くの応用があり,重要性が高い.本研究では,新しいキー順序保存型構造化オーバレイネットワークSuzakuを提案する.Suzakuは,(1)Churn時でも最大検索ホップ数がlog_2 n程度に収まる(nはノード数),(2)キーが大小どちらの方向でも近傍ノードの検索は高速に行える,(3)構造は単純で実装が容易,といった特徴を備える.本稿ではSuzakuの詳細について述べ,シミュレーションによって既存のChord#およびSkip Graphと比較する.
A ``key-order preserving structured overlay network,'' which enables
range queries, has various applications and thus be important. In
this study, we propose a novel key-order preserving structured
overlay network ``Suzaku,'' which has the following properties: (1)
maximum lookup hops is almost log_2 n even in churn situations,
where $n$ is the number of nodes, (2) neighbor search is fast
regardless of the direction of their keys, (3) the structure is
simple and easy to implement. In this paper, we describe the
principles and detailed algorithm of Suzaku. We also show
simulation results comparing Suzaku with existing Chord# and Skip
Graph.
#Import standard math functions from math import import .docxgertrudebellgrove
#Import standard math functions
from math import *
import numpy as np
import matplotlib.pyplot as plt
#Prandtl-Meyer expansion angle function:
def nu(M,y):
return sqrt((y+1)/(y-1))*atan(sqrt((y-1)*(M**2-1)/(y+1)))-
atan(sqrt(M**2-1))
#Prandtl-Meyer Expansion angle for numeric extraction of Mach
number
def nu2(M,nu,y):
return sqrt((y+1)/(y-1))*atan(sqrt((y-1)*(M**2-1)/(y+1)))-
atan(sqrt(M**2-1))-nu
#Derivative of Prandtl-Meyer expansion angle function
def nudif(M, y = 1.25):
return sqrt(M**2-1)/(M*(1+(y-1)*M**2/2))
#Stagnation pressure from freestream pressure.
def Pstag(Pe,M,y):
return Pe*(1+(y-1)/2*M**2)**(y/(y-1))
#Stagnation pressure ratio across a shockwave with P01
calculated from Pstat and M.
def Pstagratio(M,P02,P1,y):
P01 = Pstag(P1,M,y)
f1 = 2/((y+1)*(y*M**2-(y-1)/2)**(1/(y-1)))
f2 = (((y+1)/2*M)**2/(1+(y-1)/2*M**2))**(y/(y-1))
return f1*f2-P02/P01
#Stagnation pressure ratio across a shockwave with P01
calculated from Pstat and M.
def Pstagshock(M,P1,y):#returns P02
P01 = Pstag(P1,M,y)
f1 = 2/((y+1)*(y*M**2-(y-1)/2)**(1/(y-1)))
f2 = (((y+1)/2*M)**2/(1+(y-1)/2*M**2))**(y/(y-1))
return f1*f2*P01
#Pressure across an oblique shockwave as a function of upstream
pressure, gamma, and Mach.
def Pstatshock(P,M,y,theta):
beta = shockangle(M,y,theta)[1]
return P*(1+2*y/(y+1)*((M*sin(beta))**2-1))
#Numerical derivative for this particular function with only x
(which is M) varying.
def centraldiff(func, x, A, Ast, y, h = 0.0000001):
return (func(x+h,A,Ast,y)-func(x-h,A,Ast,y))/(2*h)
#Newton's method for four-term fuction.
def Newts(func, fin,y,A,Ast, err, iMax = 100000):
x1 = fin
it = 0
ea = np.Infinity
while ea > err and it < iMax:
x0 = x1
x1 = x0 - func(x0,A,Ast,y)/
(centraldiff(func,x0,A,Ast,y))
#x1 = x0 - func(x0,A,Ast,y)/(RPdif(x0,y))
it +=1
ea = abs((x0-x1)/x1)
return x1
#Newton's method
def Newt(Mguess,nu,gamma,err,iMax=1000):
x1 = Mguess
it = 0
ea = 100000
while ea > err and it < iMax:
x0 = x1
x1 = x0 - nu2(x0,nu,gamma)/nudif(x0,gamma)
it +=1
ea = abs((x0-x1)/x1)
return x1
#Pressure across expansion fan
def Pexpand(M1, M2, P1, y):
top = 1+(y-1)/2*M1**2
bot = 1+(y-1)/2*M2**2
return P1*(top/bot)**(y/(y-1))
#Explicit solution for beta angle. Requires theta input in
degrees.
def shockangle(M,y,thd):
th = thd*pi/180
lt1 = (M**2-1)**2
lt2 = (1+(y-1)/2*M**2)
lt3 = (1+(y+1)/2*M**2)
l = (lt1-3*lt2*lt3*tan(th)**2)**.5
xt1 = (M**2-1)**3
xt2 = lt2
xt3 = (1+(y-1)/2*M**2+(y+1)/4*M**4)
x = (xt1-9*xt2*xt3*tan(th)**2)/l**3
tanb = []
for i in range(2):
tt1 = (M**2-1)
tt2 = 2*l*cos((4*pi*float(i)+acos(x))/3)
tt3 = 3*(1+(y-1)/2*M**2)*tan(th)
tanb.append((tt1+tt2)/tt3)
return (atan(tanb[0]),atan(tanb[1]))
#Ma ...
Poles and Zeros of a transfer function are the frequencies for which the value of the denominator and numerator of transfer function becomes zero respectively. poles and zeros define the performance of a system.
Abstract
キーの値による範囲検索が可能なキー順序保存型構造化オーバレイネットワークは多くの応用があり,重要性が高い.本研究では,新しいキー順序保存型構造化オーバレイネットワークSuzakuを提案する.Suzakuは,(1)Churn時でも最大検索ホップ数がlog_2 n程度に収まる(nはノード数),(2)キーが大小どちらの方向でも近傍ノードの検索は高速に行える,(3)構造は単純で実装が容易,といった特徴を備える.本稿ではSuzakuの詳細について述べ,シミュレーションによって既存のChord#およびSkip Graphと比較する.
A ``key-order preserving structured overlay network,'' which enables
range queries, has various applications and thus be important. In
this study, we propose a novel key-order preserving structured
overlay network ``Suzaku,'' which has the following properties: (1)
maximum lookup hops is almost log_2 n even in churn situations,
where $n$ is the number of nodes, (2) neighbor search is fast
regardless of the direction of their keys, (3) the structure is
simple and easy to implement. In this paper, we describe the
principles and detailed algorithm of Suzaku. We also show
simulation results comparing Suzaku with existing Chord# and Skip
Graph.
#Import standard math functions from math import import .docxgertrudebellgrove
#Import standard math functions
from math import *
import numpy as np
import matplotlib.pyplot as plt
#Prandtl-Meyer expansion angle function:
def nu(M,y):
return sqrt((y+1)/(y-1))*atan(sqrt((y-1)*(M**2-1)/(y+1)))-
atan(sqrt(M**2-1))
#Prandtl-Meyer Expansion angle for numeric extraction of Mach
number
def nu2(M,nu,y):
return sqrt((y+1)/(y-1))*atan(sqrt((y-1)*(M**2-1)/(y+1)))-
atan(sqrt(M**2-1))-nu
#Derivative of Prandtl-Meyer expansion angle function
def nudif(M, y = 1.25):
return sqrt(M**2-1)/(M*(1+(y-1)*M**2/2))
#Stagnation pressure from freestream pressure.
def Pstag(Pe,M,y):
return Pe*(1+(y-1)/2*M**2)**(y/(y-1))
#Stagnation pressure ratio across a shockwave with P01
calculated from Pstat and M.
def Pstagratio(M,P02,P1,y):
P01 = Pstag(P1,M,y)
f1 = 2/((y+1)*(y*M**2-(y-1)/2)**(1/(y-1)))
f2 = (((y+1)/2*M)**2/(1+(y-1)/2*M**2))**(y/(y-1))
return f1*f2-P02/P01
#Stagnation pressure ratio across a shockwave with P01
calculated from Pstat and M.
def Pstagshock(M,P1,y):#returns P02
P01 = Pstag(P1,M,y)
f1 = 2/((y+1)*(y*M**2-(y-1)/2)**(1/(y-1)))
f2 = (((y+1)/2*M)**2/(1+(y-1)/2*M**2))**(y/(y-1))
return f1*f2*P01
#Pressure across an oblique shockwave as a function of upstream
pressure, gamma, and Mach.
def Pstatshock(P,M,y,theta):
beta = shockangle(M,y,theta)[1]
return P*(1+2*y/(y+1)*((M*sin(beta))**2-1))
#Numerical derivative for this particular function with only x
(which is M) varying.
def centraldiff(func, x, A, Ast, y, h = 0.0000001):
return (func(x+h,A,Ast,y)-func(x-h,A,Ast,y))/(2*h)
#Newton's method for four-term fuction.
def Newts(func, fin,y,A,Ast, err, iMax = 100000):
x1 = fin
it = 0
ea = np.Infinity
while ea > err and it < iMax:
x0 = x1
x1 = x0 - func(x0,A,Ast,y)/
(centraldiff(func,x0,A,Ast,y))
#x1 = x0 - func(x0,A,Ast,y)/(RPdif(x0,y))
it +=1
ea = abs((x0-x1)/x1)
return x1
#Newton's method
def Newt(Mguess,nu,gamma,err,iMax=1000):
x1 = Mguess
it = 0
ea = 100000
while ea > err and it < iMax:
x0 = x1
x1 = x0 - nu2(x0,nu,gamma)/nudif(x0,gamma)
it +=1
ea = abs((x0-x1)/x1)
return x1
#Pressure across expansion fan
def Pexpand(M1, M2, P1, y):
top = 1+(y-1)/2*M1**2
bot = 1+(y-1)/2*M2**2
return P1*(top/bot)**(y/(y-1))
#Explicit solution for beta angle. Requires theta input in
degrees.
def shockangle(M,y,thd):
th = thd*pi/180
lt1 = (M**2-1)**2
lt2 = (1+(y-1)/2*M**2)
lt3 = (1+(y+1)/2*M**2)
l = (lt1-3*lt2*lt3*tan(th)**2)**.5
xt1 = (M**2-1)**3
xt2 = lt2
xt3 = (1+(y-1)/2*M**2+(y+1)/4*M**4)
x = (xt1-9*xt2*xt3*tan(th)**2)/l**3
tanb = []
for i in range(2):
tt1 = (M**2-1)
tt2 = 2*l*cos((4*pi*float(i)+acos(x))/3)
tt3 = 3*(1+(y-1)/2*M**2)*tan(th)
tanb.append((tt1+tt2)/tt3)
return (atan(tanb[0]),atan(tanb[1]))
#Ma ...
MATLAB/Assignment 2/Bracketing (Multiple Roots) (4)/Bisection method bracketing/Thumbs.db
MATLAB/Assignment 2/Bracketing (Multiple Roots) (4)/Newton method bracketing/Thumbs.db
MATLAB/Assignment 2/Bracketing (Multiple Roots) (4)/Thumbs.db
MATLAB/Assignment 2/Thumbs.db
MATLAB/Assignment 2/Newton method - intersection of two functions (3)/Thumbs.db
MATLAB/Assignment 2/Bisecting method (1)/Thumbs.db
MATLAB/Assignment 2/Newton Method (2)/Thumbs.db
MATLAB/Assignment 1/Images/Thumbs.db
MATLAB/Assignment 1/Nano Sim Assignment 1.docx
Simulation on the Nanoscale ENG-M03: Assignment 1
Using a script file (I)
clear
format short g
N = 100;
x = linspace(-pi,pi,N)';
y = sin(x);
figure(1), plot(x,y)
Defining a function (II)
function y = sin_scale (x,sf)
y = sin(x./sf);
end
sf = 0.1;
y = sin_scale(x,sf);
figure(2), plot(x,y)
sf=[0.1 0.5 2];
N_sf = numel(sf);
sin_array = zeros(N,N_sf);
for ndx = 1: N_sf
sin_array(:,ndx) = sin_scale(x,sf(ndx));
end
figure(3),plot(x,sin_array)
Numerical Differentiation
Function
function dydx = Deriv(x,y)
N = numel(x);
dydx = zeros(N-1,1);
h= x(2)-x(1);
for ndx = 1 : N-1
dydx(ndx,:) =(y(ndx+1)-y(ndx))/h;
end
Script
clear
format short g
N=100;
x = linspace (-pi,pi,N)';
y = cos(x);
dydx = Deriv(x,y);
xd = x(1:N-1);
figure(4), plot(x,y,xd,dydx,x,-sin(x))
Numerical Integration
1. Trapezoidal Method
a) Integral
b) g=integral(@f,a,b,'ArrayValued',true)
Error = ((I-g)/g).*100 = 23.37%
2. Composite Trapezium Rule
a) function [ aproxInt ] = aproxInt(n,a,b)
function y = sumFx
y = 0;
for k = 1:n-1
y = y + feval(@f,(a+(k.*((b-a)/n))));
end
end
Totx=sumFx;
aproxInt = 0.5.*((b-a)/n).*((feval(@f,a))+(feval(@f,b))+(2.*(Totx)));
end
b) I= aproxInt(n,a,b)= 1.00002056192951
Error = ((I-g)/g).*100 = 0.00205619295078341
c) I1 = aproxInt2(5,1,2) = 0.695634920634921
I2 = aproxInt2(50,1,2) = 0.693172179310195
I3 = aproxInt2(100,1,2) = 0.693153430481824
d) g1 = log(2);
e1 = ((I1-g1)/g1).*100 = 0.358905026918763
e2 = ((I2-g1)/g1).*100 = 0.00360655730140557
e3 = ((I3-g1)/g1).*100 = 0.000901673130050152
e) number of sub-intervals needed to achieve an accuracy to 6 d.p., n=277 (adjusted manually)
3. Simpson’s Rule
MATLAB/Assignment 2/Nanosim assignment 2.docx
Simulation on the Nanoscale ENG-M03: Assignment 2
1. Bisection Method
2. Newton Method
3. Newton Method – Intersection of Two Functions
This script only takes 3 iterations to calculate the root. Newton’s method by intersection of two functions is much faster than the bisection method, but encounters problems unless the root is well defined (e.g. the wrong root may be found).
4. Bracketing (Newton Method)
4. Bracketing (Bisection Method)
MATLAB/Assignment 1/Composite Trapezium Rule(5)/aproxInt.m
%5a)
function [ aproxInt ] = aproxInt(n,a,b)
function y = sumFx
y = 0;
for k = 1:n-1
y = y + feval(@f,(a+(k.*((b-a)/n))) ...
1. 以下是小波变换的相关程序 2.Daub4 变换
function y = Daub4(f)
1.Haar 变换
% Level 1 Daub4 transform
function h = Haar(f)
r = f(2:2:end)-sqrt(3)*f(1:2:end);
s = f(1:2:end)+sqrt(3)/4*r+(sqrt(3)-
% N = length(f);
2)/4*[r(2:end), r(1)];
% a = zeros(1,N/2);
a = (1+sqrt(3))/sqrt(2)*s;
% d = zeros(1,N/2);
d = (1-sqrt(3))/sqrt(2)*(s+[r(2:end), r(1)]);
% for m = 1:N/2
y = [a, d];
% a(m) = (f(2*m-1)+f(2*m))/sqrt(2);
% d(m) = (f(2*m-1)-f(2*m))/sqrt(2);
% end Daub4 逆变换
function f = Daub4I(y)
% a = (f(1:2:end-1)+f(2:2:end))/sqrt(2); % Level 1 Inverse Daub4 Transform
% d = (f(1:2:end-1)-f(2:2:end))/sqrt(2); s = sqrt(2)/(1+sqrt(3))*y(1:end/2);
% h = [a d]; r = sqrt(2)/(1-sqrt(3))*[y(end),y(end/2+1:end-
1)]...
h = [(f(1:2:end-1)+f(2:2:end)), ...
-[s(end),s(1:end-1)];
(f(1:2:end-1)-f(2:2:end))]/sqrt(2); f = y;
f(1:2:end) = s-sqrt(3)/4*r-(sqrt(3)-
2)/4*[r(2:end),r(1)];
Haar 逆变换
f(2:2:end) = r + sqrt(3)*f(1:2:end);
function f = HaarI(h)
Daub4 K 层变换
% M = length(h)/2; function y = Daub4K(x, k)
% f = zeros(1,2*M);
% for i=1:M y = x;
% f(2*i-1:2*i) = [h(i)+h(M+i), h(i)-h(M+i)]; for i=1:k
% end
y(1:end/2^(i-1)) = Daub4(y(1:end/2^(i-1)));
end
a = h(1:end/2);
d = h(end/2+1:end); Daub4 K 层逆变换
f = reshape([a+d; a-d],1,[])/sqrt(2); function y = Daub4KI(x, k)
% Level K Inverse Daub4 Transform
K 层 Haar 变换
y = x;
function y = HaarK(f, k)
for i=k:-1:1
% k-level Haar transform
y = f; y(1:end/2^(i-1)) = Daub4I(y(1:end/2^(i-1)));
for i=1:k end
y(1:end/2^(i-1)) = Haar(y(1:end/2^(i-1)));
end 3.Daub6 变换
function y = Daub6(f)
K 层 Haar 逆变换
% level 1 Daub6 transform
function f = HaarKI(y, k)
a1 = (1+sqrt(10)+sqrt(5+2*sqrt(10)))*sqrt(2)/32;
% k-level Inverse Haar transform
a2 =
f = y;
(5+sqrt(10)+3*sqrt(5+2*sqrt(10)))*sqrt(2)/32;
for i=k:-1:1
a3 = (10-
f(1:end/2^(i-1)) = HaarI(f(1:end/2^(i-1))); 2*sqrt(10)+2*sqrt(5+2*sqrt(10)))*sqrt(2)/32;
end a4 = (10-2*sqrt(10)-
2*sqrt(5+2*sqrt(10)))*sqrt(2)/32;
a5 = (5+sqrt(10)-
3*sqrt(5+2*sqrt(10)))*sqrt(2)/32;
3. f(2:2:end) = y(end/2+1:end)+floor((f(1:2:end)+ y = f;
[f(3:2:end),f(end-1)])/2+1/2); for i = 1:k
for j = 1:2^(i-1)
5.Daub4 2D 变换
for p = 1:2^(i-1)
function y = Daub4_2D(f)
y((j-1)*m/2^(i-1)+1:j*m/2^(i-1),(p-
[m,n] = size(f); 1)*n/2^(i-1)+1:p*n/2^(i-1)) = Daub4_2D(y((j-
y = f; 1)*m/2^(i-1)+1:j*m/2^(i-1),(p-1)*n/2^(i-
for i = 1:m 1)+1:p*n/2^(i-1)));
y(i,:) = Daub4(y(i,:)); end
end
end
for i = 1:n
end
y(:,i) = Daub4(y(:,i)')';
逆变换
end
function f = Daub4p_2D_K_I(y,k)
Daub4 2D 逆变换 [m,n] = size(y);
function f = Daub4_2D_I(y) f = y;
for i = k:-1:1
[m,n] = size(y);
for j = 1:2^(i-1)
f = y;
for i = 1:m for p = 1:2^(i-1)
f(i,:) = Daub4I(f(i,:)); f((j-1)*m/2^(i-1)+1:j*m/2^(i-1),(p-
end 1)*n/2^(i-1)+1:p*n/2^(i-1)) = Daub4_2D_I(f((j-
for i = 1:n 1)*m/2^(i-1)+1:j*m/2^(i-1),(p-1)*n/2^(i-
f(:,i) = Daub4I(f(:,i)')'; 1)+1:p*n/2^(i-1)));
end end
end
Daub4 2D K 层变换 end
function y = Daub4_2D_K(f,k)
7 图片保存信息量为原来的 99.99%
y = f; function f = Daub4p_2D_K_I(y,k)
for i = 1:k [m,n] = size(y);
f = y;
y(1:end/2^(i-1),1:end/2^(i-1)) = for i = k:-1:1
Daub4_2D(y(1:end/2^(i-1),1:end/2^(i-1)));
for j = 1:2^(i-1)
end
for p = 1:2^(i-1)
Daub4 2D K 层逆变换 f((j-1)*m/2^(i-1)+1:j*m/2^(i-1),(p-
function f = Daub4_2D_K_I(y,k) 1)*n/2^(i-1)+1:p*n/2^(i-1)) = Daub4_2D_I(f((j-
1)*m/2^(i-1)+1:j*m/2^(i-1),(p-1)*n/2^(i-
f = y; 1)+1:p*n/2^(i-1)));
for i = k:-1:1
end
f(1:end/2^(i-1),1:end/2^(i-1)) =
end
Daub4_2D_I(f(1:end/2^(i-1),1:end/2^(i-1)));
end end
6.Daub4 2D P 变换
function y = Daub4p_2D_K(f,k)
[m,n] = size(f);